package br.ifrr.gepro.projeto.dao;

import br.ifrr.gepro.util.BaseDao;
import br.ifrr.gepro.util.Conexao;
import br.ifrr.gepro.util.DAOException;
import java.util.List;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.Transaction;

/**
 *
 * @author rafael
 */
public class ProjetoDao extends BaseDao{
     private Session session = null;
     private Transaction transaction = null;
    
    public List listarPorCliente(Integer cliente) throws DAOException {
        try {
            session = Conexao.getInstace();
            List objs = session.createQuery("FROM " + getClasseVO()+" WHERE fk_proj="+cliente).list();
            session.flush();
            return objs;
        } catch (HibernateException e) {
            throw new DAOException(e);
        } finally {
            try {
                if (transaction != null) {
                    if (!transaction.wasCommitted()) {
                        transaction.rollback();
                    }
                    if (session != null) {
                        session.close();
                    }
                }
            } catch (HibernateException e1) {
                throw new DAOException(e1);
            }
        }
    }
}
